#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header

def report(msg, file1, file2) :
    # 3rd SMTP service
    mail_host = "smtp.exmail.qq.com"
    mail_user = "cheng.xiyu@moretv.com.cn"
    mail_pass = "cxy88400206"

    sender = "cheng.xiyu@moretv.com.cn"
    receivers = ["cheng.xiyu@whaley.cn"
                #, "chen.dong@whaley.cn"
                #, "pan.jian@whaley.cn"
                ]

    # message = MIMEText("statistic Python send ...", "plain", "utf-8")
    message = MIMEMultipart()

    message.attach(MIMEText(msg, "plain", "utf-8"))
    message["From"] = Header("statistic python", "utf-8")
    message["To"] = Header("p2p team", "utf-8")

    subject = "Statistic Python Report"
    message["Subject"] = Header(subject, "utf-8")

    att1 = MIMEText(open(file1, "rb").read(), "base64", "utf-8")
    att1["Content-Type"] = "application/octet-stream"
    att1["Content-Disposition"] = "attachment; filename='data.xls'"
    message.attach(att1)

    att2 = MIMEText(open(file2, "rb").read(), "base64", "utf-8")
    att2["Content-Type"] = "application/octet-stream"
    att2["Content-Disposition"] = "attachment; filename='report.sql'"
    message.attach(att2)

    try :
        smtpObj = smtplib.SMTP()
        smtpObj.connect(mail_host, 25)
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(sender, receivers, message.as_string())
    except smtplib.SMTPException :
        print "Error : send mail failed"

if __name__ == "__main__" :
    report("statistic Python send test ...")
